<template>
	<view class="main">
		<view class="box">
			<view class="card_content" v-for="(n,k) in list" :key="k" @click="goNewProject(n)">
				<view class="card">
					<view class="card_title">
						{{mySubTitle(n.title,7)}}
					</view>
					<view class="card_content">
						{{mySubTitle(n.discription,17)}}
					</view>
				</view>
				<view class="reference">
					引用模板
				</view>
			</view>
			<view class="job_empty" v-if="empty">
				<view class="">
					<u-image width="335rpx" height="320rpx" :src="emptyImg"></u-image>
				</view>
				<view class="empty_text">
					{{emptyText}}
				</view>
			</view>
		</view>
		<go-nav></go-nav>
	</view>
</template>

<script>
	import {
		wenjuanList
	} from '@/api/index.js'
	import pageMixinNorRequestNoLimit from '@/utils/pageMixinNorRequestNoLimit.js' //在需要引入的组件中引入
	export default {
		mixins: [pageMixinNorRequestNoLimit],
		data() {
			return {
				teamId:'',
				emptyImg: require('@/static/img/empty_hcem.png'),
				emptyText:'暂无问卷模板'
				// list: [{
				// 		id:1,
				// 		title: '糖尿病患者',
				// 		discription: '通过定时检测空腹和餐后血糖水平，了解个部位，以'
				// 	}
				// ]
			}
		},
		onLoad() {
			this.clearPageStatus()
			this.getTeam()
		},
		methods: {
			async getMyList(obj) { //请求,这个最好在使用那个组件中使用，这个地方可以扩展接参数
				let params = {}
				let ress = uni.getStorageSync('myTeam')
				if (ress && ress?.code == 200) {
					this.teamId = ress.data.id
				} 
				if (this.teamId) { //有团队传团队id。没有传个人id
					params.teamId = this.teamId
				} else {
					//let userId = uni.getStorageSync('userinfo').user.userId
					params.teamId = 0
				}
				let res = await wenjuanList({
					...obj,
					...params
				})
				//console.log(res);
				return res
			},
			goNewProject(obj) {
				this.$store.commit('TEMPlateId',obj.id)  //所选模板id
				this.$store.commit('PICKTemplate', obj)  //所选模板
				uni.navigateBack({
					delta: 1
				})
				// uni.redirectTo({
				// 	url: '/pages/follow/rulejob'
				// });
			}
		},
		computed: {
			// lists() {
			// 	return this.$store.state.doc.JobTempList
			// },
			mySubTitle(strings, num) {
				return (strings, num) => {
					if(strings){
						let s = strings.toString()
						if (s.length < num) {
							return s
						} else {
							return s.slice(0, num) + '...'
						}
					}else{
						return ''
					}
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.main {
		background-color: #f8f8f8;
		position: absolute;
		width: 100%;
		min-height: 100vh;

		.box {
			display: flex;
			flex-wrap: wrap;

			.card_content {
				margin: 20rpx 0 22rpx 24rpx;
				padding: 0 24rpx;
				background-color: white;
				width: 340rpx;
				//height: 160rpx;
				border-radius: 20rpx;

				.card {

					.card_title {
						font-weight: bold;
						font-size: 34rpx;
						color: #212121;
						line-height: 1.2;
						padding: 24rpx 0 0 24rpx;
					}

					.card_content {
						padding: 12rpx 24rpx 24rpx 0;
						font-size: 30rpx;
						color: #999999;
						line-height: 1.5;
						width: 292rpx;
						border-bottom: 1px solid #e8e8e8;
					}
				}

				.reference {
					font-weight: 500;
					font-size: 32rpx;
					color: #4DC0D9;
					line-height: 1.5;
					text-align: center;
					padding: 24rpx 0;
				}
			}
			.job_empty {
				width: 100%;
				padding-top: 126rpx;
				min-height: 100vh;
				padding-bottom: 210rpx;
				display: flex;
				flex-direction: column;
				//justify-content: center;
				align-items: center;
			
				.empty_text {
					font-weight: 500;
					font-size: 36rpx;
					color: #C7C7C7;
					line-height: 1.5;
					text-align: center;
				}
			}
		}
	}
</style>